<template>
    <div class="cmt-content">
        <h3>发表评论</h3>
        <hr>
        <textarea placeholder="输如要BB的内容"></textarea>
        <mt-button type="primary" size="large">发表评论</mt-button>
        <div class="cmt-list">
            <div class="cmt-item" v-for="(item,i) in comments" :key="item.add_time">
                <div class="cmt-title">第{{i+1 }}楼&nbsp;&nbsp;用户:&nbsp{{item.user_name}}&nbsp;发表时间: {{item.add_time|dateformat}}</div>
                <div class="cmt-body">{{item.content}}</div>
            </div>

        </div>
        <mt-button type="danger" size="large" plain @click="getMore()">加载更多</mt-button>
    </div>
</template>

<script>
    import { Toast } from "mint-ui"
    export default {
        name: "comments",
        data(){
            return{
                pageindex: 1,
                comments: []
            }
        },
        created(){
            this.getComments()
        },
        methods:{
            getMore(){
                this.pageindex++;
                this.getComments()
            },
            getComments(){
                this.$http.get('getComments/'+this.id+'?pageindex='+
                    this.pageindex).then(result =>{
                        if(result.body.status === 0){
                            this.comments = this.comments.concat(result.body.message);
                        }else{
                            Toast("展示")
                        }
                })
            }
        },
        props: ["id"]
    }
</script>

<style lang="scss" scoped>
    .cmt-content{
        h3{
            font-size: 16px;
        }
        textarea{
            font-size: 14px;
            height: 85px;
            margin: 0;
        }

        .cmt-list{
            margin: 10px 0;
            .cmt-item{
                font-size: 13px;
                .cmt-title{
                    line-height: 30px;
                    background-color: #cccccc;
                }
                .cmt-body{
                    line-height: 35px;
                    text-indent: 2em;
                }
            }
        }
    }
</style>
